package com.wk.arth.od;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * 静态代码扫描
 * M 缓存一个 需要金币 5
 * 扫描的文件序号      2 2 2 2 2 5 2 2 2
 * 每个文件扫描的金币   3 3 3 3 3 1 3 3 3
 * 使用缓存策略， 需要花费最少金币 9
 * @author wukai
 * @date 2023/4/28 21:29
 */
public class JintaiDaimaSaoMiao {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = Integer.valueOf(sc.nextLine());
        Integer[] f = Arrays.stream(sc.nextLine().split(" ")).map(item->Integer.valueOf(item)).toArray(Integer[]::new);
        Integer[] c = Arrays.stream(sc.nextLine().split(" ")).map(item->Integer.valueOf(item)).toArray(Integer[]::new);
        System.out.println(getResult(f,c,m));
    }

    private static int getResult(Integer[] f, Integer[] c, int m) {
        Map<Integer,Integer> countMap = new HashMap<>();
        Map<Integer,Integer> priceMap = new HashMap<>();
        for (int i = 0; i < f.length; i++) {
            if(countMap.containsKey(f[i])){
                countMap.put(f[i], countMap.get(f[i])+1);
            }else{
                countMap.put(f[i], 1);
                priceMap.put(f[i],c[i]);
            }
        }
        int res = 0;
        for (Integer num : countMap.keySet()) {
            int cost = priceMap.get(num);
            int noCache = cost+m;
            int cache = countMap.get(num)*cost;
            res+=Math.min(noCache,cache);
        }
        return res;
    }


}
